package com.stox.manager.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.stox.manager.CountryManager;
import com.stox.model.Country;
import com.stox.repository.CountryRepository;

@Component
@Transactional
public class CountryManagerImpl implements CountryManager{

	@Autowired
	private CountryRepository countryRepository;

	@Override
	public long count() {
		return countryRepository.count();
	}
	
	@Override
	@Cacheable(cacheName)
	public List<Country> findAll() {
		return countryRepository.findAll();
	}
	
	@Override
	@Cacheable(cacheName)
	public Country findOne(Long id) {
		return countryRepository.findOne(id);
	}

	@Override
	@Transactional
	@CachePut(value=cacheName, key="#country.id")
	public Country save(Country country) {
		return countryRepository.saveAndFlush(country);
	}
	
}
